//
//  YDVerticalStockBuyController.m
//  PeiZiWangBei
//
//  Created by LK-IOS on 2018/1/2.
//  Copyright © 2018年 LK-IOS. All rights reserved.
//

#import "YDVerticalStockBuyController.h"
#import "YDQuestionController.h"//问询界面
#import "YDVerticalDetailNewsCell.h"
#import "YDVerticalDetailTableHeaderView.h"
#import "YDVerticalDetailTopView.h"
#import "YDFreeAdvertViewController.h"
#import "YDBuyStrategyController.h"
#import "YDStockSearchViewController.h"

#import "YDSingleStockNewsModel.h"
#import "YDSingleStockIntroductionModel.h"
#import "YDSingleStockFinanceModel.h"
#import "YDVerticalDetailIntroductionCell.h"
#import "YDVerticalDetailFinanceCell.h"
#import "YDVerticalStockNewDetailController.h"
#import "YDBuyOptionsViewController.h"


typedef enum
{
    News = 1,//资讯
    Introduction,//简介
    Notice,//公告
    Report,//年报
    Finance//财务
}StockNewsType;


@interface YDVerticalStockBuyController ()<UITableViewDelegate , UITableViewDataSource , SYVerticalDetailTableHeaderViewDelegate,SYVerticalDetailTopViewDelegate>

@property (nonatomic , strong) NSMutableDictionary *stockDict;

//tableView
@property (nonatomic , weak) UITableView *tableView;

//YDVerticalDetailTopView
@property (nonatomic , weak) YDVerticalDetailTopView *topView;

//当前页码
@property (nonatomic , assign) NSInteger cureentPage;

@property (nonatomic , assign) StockNewsType newType;

//新闻
@property (nonatomic , strong) NSMutableArray *newsModelArray;
//简介
@property (nonatomic , strong) NSMutableArray *introductionModelArray;
//财务
@property (nonatomic , strong) NSMutableArray *financeModelArray;

//定时器
@property (nonatomic , strong) NSTimer *timer;
//是不是正在刷新
@property (nonatomic , assign) BOOL timerIsRunning;

@end

@implementation YDVerticalStockBuyController

-(NSMutableDictionary *)stockDict
{
    if (_stockDict == nil) {
        _stockDict = [NSMutableDictionary dictionary];
    }
    return _stockDict;
}
-(NSMutableArray *)newsModelArray
{
    if (_newsModelArray == nil) {
        _newsModelArray = [NSMutableArray array];
        
    }
    return _newsModelArray;
}
-(NSMutableArray *)introductionModelArray
{
    if (_introductionModelArray == nil) {
        _introductionModelArray = [NSMutableArray array];
    }
    return _introductionModelArray;
}
-(NSMutableArray *)financeModelArray
{
    if (_financeModelArray == nil) {
        _financeModelArray = [NSMutableArray array];
    }
    return _financeModelArray;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor colorWithHexString:mainGray];
    [self tableView];
    [self topView];
    [self loadStockDetailData];
    _newType = News;
    [self setUpNav];
    [self setUpDataManger];
    //加载新闻资讯
    [self loadNewsData];
    
}
-(void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
    [self openTimer];
    [self viewOpenTimer];
}
-(void)viewDidDisappear:(BOOL)animated
{
    [super viewDidDisappear:animated];
    [self stopTimer];
    [self viewStopTimer];
}
-(void)addNotification
{
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(openTimer) name:UIApplicationDidBecomeActiveNotification object:nil];
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(stopTimer) name:UIApplicationDidEnterBackgroundNotification object:nil];
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(stopTimer) name:UIApplicationWillTerminateNotification object:nil];
}
-(void)dealloc
{
    DDLog(@"dealloc")
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}
-(void)openTimer
{
    [self.topView openTimer];
    [self viewOpenTimer];
}
-(void)stopTimer
{
    [self.topView stopTimer];
    [self viewStopTimer];
}

//定时器
-(void)viewOpenTimer
{
    if (self.timer)return;
    if (![NSDate stockTradingTimeJudgment])return;
    DDLog(@"开启定时器")
    self.timer = [NSTimer scheduledTimerWithTimeInterval:3 target:self selector:@selector(timeLoadStockDetailData) userInfo:nil repeats:YES];
    [[NSRunLoop mainRunLoop] addTimer:self.timer forMode:NSRunLoopCommonModes];
}
-(void)viewStopTimer
{
    if (!self.timer)return;
    DDLog(@"关闭定时器")
    [self.timer invalidate];
    self.timer = nil;
}

//加载工具
-(void)setUpDataManger
{
    MJGIFHeader *header = [MJGIFHeader headerWithRefreshingTarget:self refreshingAction:@selector(loadNewsData)];
    //隐藏时间
    header.lastUpdatedTimeLabel.hidden = YES ;
    //隐藏状态
    header.stateLabel.hidden = YES ;
    self.tableView.mj_header = header;
    
    MJGIFFooter *footer = [MJGIFFooter footerWithRefreshingTarget:self refreshingAction:@selector(loadMoreNewsData)];
    footer.stateLabel.hidden = YES;
    self.tableView.mj_footer = footer;
    self.tableView.mj_footer.hidden = YES;
}

/**
 设置导航栏
 */
-(void)setUpNav
{
    self.title = self.isNormal ? @"发布策略" : @"股票详情";
    if (self.isNormal) {
        UIBarButtonItem *rightItemBtn = [UIBarButtonItem imageWithNormalImage:[UIImage imageNamed:@"h-guize"] hightImage:[UIImage imageNamed:@"h-guize"] addTarget:self action:@selector(rightItemButtonClick:)];
        self.navigationItem.rightBarButtonItem = rightItemBtn;
    }
}
-(void)rightItemButtonClick:(UIButton *)button
{
    YDQuestionController *vc = [[YDQuestionController alloc] init];
    vc.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:vc animated:YES];
    
}
#pragma mark -SYVerticalDetailTopViewDelegate
- (void)didSlectedBtn:(NSString *)title
{
    if ([title isEqualToString:@"更换股票"])
    {
        YDStockSearchViewController *vc = [[YDStockSearchViewController alloc] init];
        vc.searchStyle = Search_Present;
        LK(weakSelf);
        
        [vc setDissBack:^(NSString *stockName, NSString *stockCode) {
            weakSelf.stockName = stockName;
            weakSelf.stockCode = stockCode;
            [weakSelf loadStockDetailData];
        }];
        
        
        YDBaseNavigationController *baseNav = [[YDBaseNavigationController alloc] initWithRootViewController:vc];
        [self presentViewController:baseNav animated:YES completion:nil];
        
    }else if ([title isEqualToString:@"股票交易"] || [title isEqualToString:@"发布"])
    {
        if (self.isActivity) {
            //活动进来
            YDFreeAdvertViewController *vc = [[YDFreeAdvertViewController alloc] init];
            vc.stockCode = self.stockCode;
            [self.navigationController pushViewController:vc animated:YES];
        }
        else
        {
            YDBuyStrategyController *vc = [[YDBuyStrategyController alloc] init];
            vc.stockCode = self.stockCode;
            vc.hidesBottomBarWhenPushed =YES;
            [self.navigationController pushViewController:vc animated:YES];
        }
    }else if ([title isEqualToString:@"自选"]){
        if (![SYUserInformation sharedInstance].isLogin) {
            [self presentLoginVC];
            return;
        }else{
            //获取id
            NSString *instrumentId = self.stockDict[@"instrumentId"];
            if (!instrumentId)return;
            BOOL favorite = [self.stockDict[@"favorite"] boolValue];
            [[SYProgressHUD sharedInstance] showMBHudWithSting:kLoadingText];
            NSMutableDictionary *pramas = [NSMutableDictionary dictionary];
            if (favorite) {
                [pramas setObject:instrumentId forKey:@"stockCodes"];
            }else{
                [pramas setObject:instrumentId forKey:@"stockCode"];
            }
            RequestType type = favorite ? DeleteOptionalStock : AddOptionalStock;
            NSString *postString = favorite ? @"已从自选中移除" : @"成功添加到自选，请在自选中查看";
            [BaseNetRequest sessionRequestWithparameters:pramas method:POSTMethod requstType:type WithSuccessBlock:^(NSDictionary *resultDict) {
                [[SYProgressHUD sharedInstance] dismissMBWithTime:0];
                if ([resultDict[@"code"] integerValue] == 200) {//注册成功
                    if (favorite) {
                        [self.stockDict setObject:@"0" forKey:@"favorite"];
                    }else{
                        [self.stockDict setObject:@"1" forKey:@"favorite"];
                    }
                    
                    self.topView.stockDict = self.stockDict;
                    [[NavTipsView defaultTipsView] showTipsBannerInView:self.view WithType:NavTipsViewTypeSuccess text:postString isExistNav:YES];
                    
                }else{
                    [[NavTipsView defaultTipsView] showTipsBannerInView:self.view WithType:NavTipsViewTypeMessage text:resultDict[@"message"] isExistNav:YES];
                }
            } failBlock:^(NSError *error) {
                [[SYProgressHUD sharedInstance] dismissMBWithTime:0];
                [[NavTipsView defaultTipsView] showTipsBannerInView:self.view
                                                                WithType:NavTipsViewTypeMessage
                                                                    text:kNet_Error_ConnectionLost
                                                              isExistNav:YES];
            }];
            
        }
    }else if ([title isEqualToString:@"策略申购"]){//期权交易
        if (self.isPopToRootC) {
            [self.navigationController popViewControllerAnimated:YES];
        }else{//点击单只股票进来
            YDBuyOptionsViewController *vc = [[YDBuyOptionsViewController alloc] init];
            vc.stockCode = [self.stockDict objectForKey:@"instrumentId"];
            vc.hidesBottomBarWhenPushed = YES;
            [self.navigationController pushViewController:vc animated:YES];
        }
        
    }
}

- (void)presentLoginVC
{
    YDLoginController *loginVC = [[YDLoginController alloc] init];
    loginVC.loginStyle = Login_Present;
    YDBaseNavigationController *baseNav = [[YDBaseNavigationController alloc] initWithRootViewController:loginVC];
    [self presentViewController:baseNav animated:YES completion:nil];
}

/**
 tableView
 */
-(UITableView *)tableView
{
    if (_tableView == nil) {
        
        UITableView *tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, LKScreenW, self.view.height - self.tabBarController.tabBar.height - 10) style:UITableViewStylePlain];
        [self.view addSubview:tableView];
        tableView.backgroundColor = [UIColor whiteColor];
        tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        tableView.dataSource = self;
        tableView.delegate = self;
        tableView.estimatedRowHeight = 0;
        tableView.estimatedSectionFooterHeight = 0;
        tableView.estimatedSectionHeaderHeight = 0;
        if (isIos11) {
            tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
        }
        _tableView = tableView;
    }
    return _tableView;
}

/**
YDVerticalDetailTopView
 */
-(YDVerticalDetailTopView *)topView
{
    if (_topView == nil) {
        YDVerticalDetailTopView *topView = [YDVerticalDetailTopView verticalDetailTopViewWithStockDict:[self.stockDict copy] StockName:self.stockName StockCode:self.stockCode IsActivity:self.isActivity IsNormal:self.isNormal OptionViewStyle:self.optionStyle];
        topView.delegate = self;
        CGRect topFrame;
        if (isPhoneX) {
            topFrame = CGRectMake(0, 0, LKScreenW, rateX812(445));
        }else{
            topFrame = CGRectMake(0, 0, LKScreenW, rate750(445));
        }
        topView.frame = topFrame;
        topView.y = -topView.height;
        self.tableView.tableHeaderView = topView;
        _topView = topView;
    }
    return _topView;
}
/**
 加载单只股票详情数据
 */
-(void)loadStockDetailData
{
    NSString *url;
    if (!self.stockCode) {
        url = [NSString stringWithFormat:@"%@%@",@"/stock/market/" , @"000001"];
    }else{
        url = [NSString stringWithFormat:@"%@%@",@"/stock/market/" , self.stockCode];
    }
    NSString *baseUrl = [NSString stringWithFormat:@"%@%@",baseUrlHttp , url];
    NSString *authToken = [[SYUserDataManger sharedInstance] getUserToken];
    BaseNetRequest *request = [[BaseNetRequest alloc] initWithRequestMethod:GETMethod];
    [request sessionRequestWithDictionary:nil andURLString:baseUrl andAuthToken:authToken WithSuccessBlock:^(NSDictionary *resultDict) {
        if ([resultDict[@"code"] integerValue] == 200) {
            self.stockDict = [resultDict[@"result"] mutableCopy];
            self.topView.isTimerData = NO;
            self.topView.stockDict = [self.stockDict copy];
        }else{
            [[NavTipsView defaultTipsView] showTipsBannerInView:self.view WithType:NavTipsViewTypeMessage text:@"数据加载出错" isExistNav:YES];
        }
    } failBlock:^(NSError *error) {
        [[NavTipsView defaultTipsView] showTipsBannerInView:self.view WithType:NavTipsViewTypeMessage text:@"数据加载出错" isExistNav:YES];
    }];
}
//定时刷新单只股票信息
-(void)timeLoadStockDetailData
{
    if (self.timerIsRunning)return;
    self.timerIsRunning = YES;
    NSString *url;
    if (!self.stockCode) {
        url = [NSString stringWithFormat:@"%@%@",@"/stock/market/" , @"000001"];
    }else{
        url = [NSString stringWithFormat:@"%@%@",@"/stock/market/" , self.stockCode];
    }
    NSString *baseUrl = [NSString stringWithFormat:@"%@%@",baseUrlHttp , url];
    NSString *authToken = [[SYUserDataManger sharedInstance] getUserToken];
    BaseNetRequest *request = [[BaseNetRequest alloc] initWithRequestMethod:GETMethod];
    [request sessionRequestWithDictionary:nil andURLString:baseUrl andAuthToken:authToken WithSuccessBlock:^(NSDictionary *resultDict) {
        self.timerIsRunning = NO;
        if ([resultDict[@"code"] integerValue] == 200) {
            self.stockDict = [resultDict[@"result"] mutableCopy];
            self.topView.isTimerData = YES;
            self.topView.stockDict = [self.stockDict copy];
        }else{
        }
    } failBlock:^(NSError *error) {
        self.timerIsRunning = NO;
    }];
}



-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (_newType == News) {
        return self.newsModelArray.count;
    }else if (_newType == Introduction){
        return self.introductionModelArray.count;
    }else{
        return self.financeModelArray.count;
    }
 
    
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    if (_newType == News) {
        YDSingleStockNewsModel *model = self.newsModelArray[indexPath.row];
        return model.cellH;
    }else if (_newType == Introduction){
        YDSingleStockIntroductionModel *model = self.introductionModelArray[indexPath.row];
        return model.cellH;
    }else{
        return isPhoneX ? rateX812(460) : rate750(460);
    }
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 0;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return isPhoneX ? rateX812(40) : rate750(40);
}
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    YDVerticalDetailTableHeaderView *headerView = [YDVerticalDetailTableHeaderView headerViewWithTableView:tableView];
    headerView.delegate = self;
    return headerView;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    if (_newType == News) {
        YDVerticalDetailNewsCell *cell = [YDVerticalDetailNewsCell cellWithTableView:tableView];
        YDSingleStockNewsModel *model = self.newsModelArray[indexPath.row];
        cell.model = model;
        return cell;
    }else if (_newType == Introduction){
        YDVerticalDetailIntroductionCell *cell = [YDVerticalDetailIntroductionCell cellWithTableView:tableView];
        YDSingleStockIntroductionModel *model = self.introductionModelArray[indexPath.row];
        cell.model = model;
        return cell;

    }else{
        YDVerticalDetailFinanceCell *cell = [YDVerticalDetailFinanceCell cellWithTableView:tableView];
        YDSingleStockFinanceModel *model = self.financeModelArray[indexPath.row];
        cell.model = model;
        return cell;
    }
    
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (_newType != News)return;
    
    YDSingleStockNewsModel *model = self.newsModelArray[indexPath.row];
    YDVerticalStockNewDetailController *vc = [[YDVerticalStockNewDetailController alloc] init];
    vc.model = model;
    vc.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:vc animated:YES];
}


/**
 SYVerticalDetailTableHeaderViewDelegate
 @[@" 资讯 ", @" 简介 " , @" 公告 " , @" 年报 " , @" 财务 "];
 */
-(void)verticalDetailTableHeaderView:(YDVerticalDetailTableHeaderView *)headerView didClickButtonTag:(NSInteger)buttonTag
{
    self.tableView.mj_footer.hidden = YES;
    if (buttonTag == 0) {//资讯
        if (_newType == News)return;
        _newType = News;
        [self.newsModelArray removeAllObjects];
        [self.tableView reloadData];
        [self loadNewsData];
    }else if (buttonTag == 1){//简介
        if (_newType == Introduction)return;
        _newType = Introduction;
        [self.introductionModelArray removeAllObjects];
        [self.tableView reloadData];
        [self loadNewsData];
    }else if (buttonTag == 2){//财务
        if (_newType == Finance)return;
        _newType = Finance;
        [self.financeModelArray removeAllObjects];
        [self.tableView reloadData];
        [self loadNewsData];
    }
}

/**
 加载新闻自选
 */
-(void)loadNewsData
{
    /*
     stock_news  资讯//
     financial_summary  财务摘要
     annual_report  年度报告
     company_profile   公司简介//
     company_announcement 公司公告
     */
    self.cureentPage = 0;
    //加载的数据类型
    NSString * postString;
    NSMutableDictionary *dict = [NSMutableDictionary dictionary];
    if (_newType == News) {//新闻
        postString = @"新闻资讯加载出错";
        if (!self.stockCode) {
            [dict setObject:@"stock_news" forKey:@"type"];
            [dict setObject:[NSNumber numberWithInteger:self.cureentPage] forKey:@"page"];
            [dict setObject:[NSNumber numberWithInteger:10] forKey:@"pageSize"];
            [dict setObject:@"000001" forKey:@"code"];
        }else{
            [dict setObject:@"stock_news" forKey:@"type"];
            [dict setObject:[NSNumber numberWithInteger:self.cureentPage] forKey:@"page"];
            [dict setObject:[NSNumber numberWithInteger:10] forKey:@"pageSize"];
            [dict setObject:self.stockCode forKey:@"code"];
        }
    }else if (_newType == Introduction){//简介
        postString = @"公司简介加载出错";
        if (!self.stockCode) {
            [dict setObject:@"company_profile" forKey:@"type"];
            [dict setObject:@"000001" forKey:@"code"];
        }else{
            [dict setObject:@"company_profile" forKey:@"type"];
            [dict setObject:self.stockCode forKey:@"code"];
        }
    }else if (_newType == Finance){//财务
        postString = @"财务数据加载出错";
        if (!self.stockCode) {
            [dict setObject:@"financial_summary" forKey:@"type"];
            [dict setObject:[NSNumber numberWithInteger:self.cureentPage] forKey:@"page"];
            [dict setObject:[NSNumber numberWithInteger:10] forKey:@"pageSize"];
            [dict setObject:@"000001" forKey:@"code"];
        }else{
            [dict setObject:@"financial_summary" forKey:@"type"];
            [dict setObject:[NSNumber numberWithInteger:self.cureentPage] forKey:@"page"];
            [dict setObject:[NSNumber numberWithInteger:10] forKey:@"pageSize"];
            [dict setObject:self.stockCode forKey:@"code"];
        }
    }
    DDLog(@"dict = %@" , dict)
    
    RequestType requestType;
    if (_newType == Introduction) {
        requestType = GetCompanyProfile;
    }else{
        requestType = GetNewsListDetail;
    }
    
    [BaseNetRequest sessionRequestWithparameters:dict method:GETMethod requstType:requestType WithSuccessBlock:^(NSDictionary *resultDict) {
        [self.tableView.mj_header endRefreshing];
        if ([resultDict[@"code"] integerValue] == 200) {
            if (_newType == News) {//资讯
                [self.newsModelArray removeAllObjects];
                self.newsModelArray = [YDSingleStockNewsModel mj_objectArrayWithKeyValuesArray:resultDict[@"data"]];
                [self.tableView reloadData];
                if (self.newsModelArray.count < 10) {
                    self.tableView.mj_footer.hidden = NO;
                }else{
                    self.tableView.mj_footer.hidden = NO;
                    [self.tableView.mj_footer endRefreshing];
                }
            }else if (_newType == Introduction){
                [self.introductionModelArray removeAllObjects];
                NSDictionary *dict = resultDict[@"data"];
                if ([dict count]) {
                    [self.introductionModelArray addObject:[YDSingleStockIntroductionModel mj_objectWithKeyValues:resultDict[@"data"]]];
                }
                
                [self.tableView reloadData];
                
            }else if (_newType == Finance){
                [self.financeModelArray removeAllObjects];
                self.financeModelArray = [YDSingleStockFinanceModel mj_objectArrayWithKeyValuesArray:resultDict[@"data"]];
                [self.tableView reloadData];
                if (self.financeModelArray.count < 10) {
                    self.tableView.mj_footer.hidden = NO;
                }else{
                    self.tableView.mj_footer.hidden = NO;
                    [self.tableView.mj_footer endRefreshing];
                }
                
            }
            
        }else{
            [self.tableView.mj_header endRefreshing];
            [[SYProgressHUD sharedInstance] showSVOnlytextWithText:postString];
            [[SYProgressHUD sharedInstance] dismissSVWithTime:1];
        }
    } failBlock:^(NSError *error) {
        [self.tableView.mj_header endRefreshing];
        [[SYProgressHUD sharedInstance] showSVOnlytextWithText:postString];
        [[SYProgressHUD sharedInstance] dismissSVWithTime:1];
    }];

}

-(void)loadMoreNewsData
{
    //加载的数据类型
    NSString *postString;
    NSMutableDictionary *dict = [NSMutableDictionary dictionary];
    if (_newType == News) {//新闻
        postString = @"新闻资讯加载出错";
        if (!self.stockCode) {
            [dict setObject:@"stock_news" forKey:@"type"];
            [dict setObject:[NSNumber numberWithInteger:self.cureentPage + 1] forKey:@"page"];
            [dict setObject:[NSNumber numberWithInteger:10] forKey:@"pageSize"];
            [dict setObject:@"000001" forKey:@"code"];
        }else{
            [dict setObject:@"stock_news" forKey:@"type"];
            [dict setObject:[NSNumber numberWithInteger:self.cureentPage + 1] forKey:@"page"];
            [dict setObject:[NSNumber numberWithInteger:10] forKey:@"pageSize"];
            [dict setObject:self.stockCode forKey:@"code"];
        }
    }else if (_newType == Introduction){//简介
        return;
    }else if (_newType == Finance){//财务
        postString = @"财务数据加载出错";
        if (!self.stockCode) {
            [dict setObject:@"financial_summary" forKey:@"type"];
            [dict setObject:[NSNumber numberWithInteger:self.cureentPage + 1] forKey:@"page"];
            [dict setObject:[NSNumber numberWithInteger:10] forKey:@"pageSize"];
            [dict setObject:@"000001" forKey:@"code"];

        }else{
            [dict setObject:@"financial_summary" forKey:@"type"];
            [dict setObject:[NSNumber numberWithInteger:self.cureentPage + 1] forKey:@"page"];
            [dict setObject:[NSNumber numberWithInteger:10] forKey:@"pageSize"];
            [dict setObject:self.stockCode forKey:@"code"];
        }
    }
    DDLog(@"dict = %@" , dict)
    [BaseNetRequest sessionRequestWithparameters:dict method:GETMethod requstType:GetNewsListDetail WithSuccessBlock:^(NSDictionary *resultDict) {
        DDLog(@"%@" , resultDict)
        [self.tableView.mj_footer endRefreshing];
        if ([resultDict[@"code"] integerValue] == 200) {
            
            self.cureentPage += 1;
            
            if (_newType == News) {//资讯
                NSMutableArray *array = [YDSingleStockNewsModel mj_objectArrayWithKeyValuesArray:resultDict[@"data"]];
                [self.newsModelArray addObjectsFromArray:array];
                [self.tableView reloadData];
                if (array.count < 10) {
                    self.tableView.mj_footer.hidden = NO;
                    [self.tableView.mj_footer endRefreshingWithNoMoreData];
                }else{
                    self.tableView.mj_footer.hidden = NO;
                    [self.tableView.mj_footer endRefreshing];
                }
            }else if (_newType == Introduction){
                
            }else if (_newType == Finance){
                NSMutableArray *array = [YDSingleStockFinanceModel mj_objectArrayWithKeyValuesArray:resultDict[@"data"]];
                [self.financeModelArray addObjectsFromArray:array];
                [self.tableView reloadData];
                if (array.count < 10) {
                    self.tableView.mj_footer.hidden = NO;
                    [self.tableView.mj_footer endRefreshingWithNoMoreData];
                }else{
                    self.tableView.mj_footer.hidden = NO;
                    [self.tableView.mj_footer endRefreshing];
                }
            }
            
        }else{
            [self.tableView.mj_footer endRefreshing];
            [[SYProgressHUD sharedInstance] showSVOnlytextWithText:postString];
            [[SYProgressHUD sharedInstance] dismissSVWithTime:1];
        }
    } failBlock:^(NSError *error) {
        [self.tableView.mj_footer endRefreshing];
        [[SYProgressHUD sharedInstance] showSVOnlytextWithText:postString];
        [[SYProgressHUD sharedInstance] dismissSVWithTime:1];
    }];
}


@end

